﻿package Cain
{
	import flash.net.SharedObject;
	import flash.net.SharedObjectFlushStatus;
	
	/**
	 * ...
	 * @author Cain@2009 in ADCAST
	 */
	public class SaveData
	{
		var disk:SharedObject;
		public function SaveData(_name:String)
		{
			disk = SharedObject.getLocal(_name);
		}
		public function save(dd:Object):Boolean 
		{
			var f:Boolean;
			disk.data.dd = dd;
			try {
				switch (disk.flush()) 
				{
					case SharedObjectFlushStatus.FLUSHED:
						f= true;
						break;
					case SharedObjectFlushStatus.PENDING:
						//trace("no memary");
						f= false;
						break;
				}
			}catch (e:Error)
			{
				//trace(e);
				return false;
			}
			return f;
		}
		public function load():Boolean
		{
			if (disk.size>0) 
			{
				return true;
				//trace(disk.data.name);
			}else {
				return false;
			}
		}
		public function get data():Object 
		{
			return disk.data.dd;
		}
	}
	
}